package algorithm.poj.p1000;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLDecoder;
import java.util.LinkedList;

/**
 * 分析：
 * 
 * 实现：
 * 
 * 经验：
 * 
 * 教训：
 * 
 * @author wong.tong@gmail.com
 *
 */
public class P1028 {

	public static void main(String[] args) throws Exception {

		InputStream input = null;
		if (false) {
			input = System.in;
		} else {
			URL url = P1028.class.getResource("P1028.txt");
			File file = new File(URLDecoder.decode(url.getPath(), "UTF-8"));
			input = new FileInputStream(file);
		}
		
		BufferedReader stdin = new BufferedReader(new InputStreamReader(input));

		String line = stdin.readLine();
		LinkedList<String> forward = new LinkedList<String>();
		LinkedList<String> backward = new LinkedList<String>();
		String site = "http://www.acm.org/";	//current site
		while (!"QUIT".equals(line)) {
			if (line.startsWith("VISIT")) {
				backward.push(site);
				site = line.substring(6).trim();
				while (!forward.isEmpty()) forward.pop();
				System.out.println(site);
			} else if (line.startsWith("BACK")) {
				if (backward.isEmpty()) {
					System.out.println("Ignored");
				} else {
					forward.push(site);
					site = backward.pop();
					System.out.println(site);
				}
			} else if (line.startsWith("FORWARD")) {
				if (forward.isEmpty()) {
					System.out.println("Ignored");
				} else {
					backward.push(site);
					site = forward.pop();
					System.out.println(site);
				}
			}
			line = stdin.readLine();
		}
	}
}